<?php
class Quyen_model extends CI_Model {
    
    function __construct()
    {
        parent::__construct();
    }
    function themQuyen($userID,$dsQuyen)
    {
        foreach($dsQuyen as $row)
        {
            $data=array(
            'id_nguoidung'=>$userID,
            'id_quyen'=>$row
            );
        $result=$this->db->insert('nguoidung_quyen',$data);
        }
        return $result;
    }
    function getIdQuyen($tenQuyen)
    {
        $this->db->select('id_quyen');
        $this->db->where('ten_quyen',$tenQuyen);
        $query=$this->db->get('quyen');
        if($query)
            {
                return $query->row()->id_quyen;
            }
            return false;
    }
    function dsQuyen($nhomquyen)
    {
        $this->db->where('nhom_quyen',$nhomquyen);
        $query=$this->db->get('quyen');
        return $query->result();
    }
    function deleteQuyen($userID)
        {
            $this->db->where('id_nguoidung',$userID);
            $query=$this->db->delete('nguoidung_quyen');
            return $query;
        }
    function getListQuyen($userID)
    {
        $this->db->where('id_nguoidung',$userID);
        $this->db->select('id_quyen');
        $query=$this->db->get('nguoidung_quyen');
        return $query->result_array();
    }
}
?>